{{template "main-top" .}}

<div class="lgn-head">
    {{if .Linking}}
    <h1>{{t "SelectAccount.TitleLinking"}}</h1>
    <p>{{t "SelectAccount.DescriptionLinking"}}{{if .OrgName}}
        {{t "SelectAccount.MustBeMemberOfOrg" "OrgName" .OrgName}}{{end}}</p>
    {{else}}
    <h1>{{t "SelectAccount.Title"}}</h1>
    <p>{{t "SelectAccount.Description"}}{{if .OrgName}}
        {{t "SelectAccount.MustBeMemberOfOrg" "OrgName" .OrgName}}
        {{end}}
    </p>
    {{end}}
</div>


<form action="{{ userSelectionUrl }}" method="POST">

    {{ .CSRF }}

    <input type="hidden" name="authRequestID" value="{{ .AuthReqID }}" />

    <div class="lgn-account-selection">
        {{ if .Users }}
        {{ $displayLoginNameSuffix := and .OrgID (not .DisplayLoginNameSuffix)}}
        {{ $orgName := .OrgName }}
        {{ range $user := .Users }}
        {{ $sessionState := (printf "SelectAccount.SessionState%v" $user.UserSessionState) }}
        {{if $user.SelectionPossible}}
        <button type="submit" name="userID" value="{{$user.UserID}}" class="lgn-account" 
        {{if not $user.SelectionPossible}}disabled title="{{t "Errors.User.NotAllowedOrg"}}"{{end}}>
            <div class="left">
                <div class="lgn-avatar" {{if not $user.AvatarKey}}loginname="{{$user.LoginName}}"{{end}}>
                    {{if $user.AvatarKey}}
                        <img class="avatar-img" src="{{ avatarResource $user.ResourceOwner $user.AvatarKey }}" alt="user-avatar">
                    {{else}}
                        <span class="initials">A</span>
                    {{end}}
                </div>
            </div>
            <div class="lgn-names">
                <p class="lgn-displayname">{{$user.DisplayName}}</p>
                <p class="lgn-loginname">{{if and $displayLoginNameSuffix $user.SelectionPossible}}{{$user.UserName}}{{else}}{{$user.LoginName}}{{end}}</p>
                {{if $user.UserSessionState }}
                <p class="lgn-session-state i{{$user.UserSessionState}}">{{t $sessionState}}</p>
                {{end}}
            </div>
            <span class="fill-space"></span>
            <i class="lgn-icon-angle-right-solid"></i>
        </button>
        {{ end }}
        {{ end }}
        {{ end }}
        <button type="submit" name="userID" value="0" class="lgn-account">
            <div class="left">
                <div class="lgn-avatar transparent">
                    <i class="lgn-icon-user-plus-solid account-add"></i>
                </div>
            </div>
            <div class="lgn-names">
                <p>{{t "SelectAccount.OtherUser"}}</p>
            </div>
            <span class="fill-space"></span>
            <i class="lgn-icon-angle-right-solid"></i>
        </button>
    </div>
</form>

{{template "main-bottom" .}}